/********************************************************************************
 * <b>Summary: </b>
 * 文件名：BaseBiz.java
 * 版本信息：$Rev: 1.0.0 $
 * 日期：2019-09-08
 * Copyright (c) 2005, 2019 www.sunline.cn  
 * 版权所有
 * Licensed under the SUNLINE, Version 20190616 (the "License");
 * [History]
 * Version   Date       Author     				Content
 * -------- --------- ---------- ----------------------------
 * 1.0.0   2019-09-08   蒋万勇(QQ:272389138)    $1.0.0$
 ********************************************************************************/

package com.yishe.biz;


import com.yishe.utils.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

/**
 * Created by jiangwy
 * Date: 2019/9/8
 * Time: 15:13
 * Version 1.0.0
 */
public abstract class BaseBiz<M extends Mapper<T>, T> {
    @Autowired
    protected M mapper;

    public void setMapper(M mapper) {
        this.mapper = mapper;
    }

    public T selectOne(T entity) {
        return mapper.selectOne(entity);
    }


    public T selectById(Object id) {
        return mapper.selectByPrimaryKey(id);
    }


    public List<T> selectList(T entity) {
        return mapper.select(entity);
    }


    public List<T> selectListAll() {
        return mapper.selectAll();
    }


    public Long selectCount(T entity) {
        return new Long(mapper.selectCount(entity));
    }


    public void insert(T entity) {
        setDefault(entity);
        mapper.insert(entity);
    }



    public void delete(T entity) {
        mapper.delete(entity);
    }


    public void deleteById(Object id) {
        mapper.deleteByPrimaryKey(id);
    }


    public void updateById(T entity) { 
        mapper.updateByPrimaryKey(entity);
    }




    public List<T> selectByExample(Object example) {
        return mapper.selectByExample(example);
    }

    public int selectCountByExample(Object example) {
        return mapper.selectCountByExample(example);
    }


    private void setDefault(T entity){
        EntityUtils.setCreatAndUpdatInfo(entity);
    }
}
